package com.cskaoyan.market.aspect;


import com.cskaoyan.market.util.ValidationUtils2;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;

/**
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2024/5/20 10:13
 * @Version 1.0
 */
@Component
@Aspect
public class ValidationAspect {

    @Pointcut("@annotation(com.cskaoyan.market.annotation.ValidParam)")
    public void pt(){}

    //什么通知？？？？？？
    @Before("pt()")
    public void valid(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if(arg instanceof BindingResult){
                ValidationUtils2.validate((BindingResult) arg);
            }
        }
    }
}
